<?php
// +----------------------------------------------------------------------
// | Author: derek <693472824@qq.com> <http://www.bloveambition.com/>
// +----------------------------------------------------------------------

namespace Blovex4\Controller;

/**
 * 系统配置控制器
 * derek <693472824@qq.com>
 */
class ConfigController extends BaseController {
    
    /**
     * 系统配置首页
     * @author derek <693472824@qq.com>
     */
    public function index() {
        
        /* 查询条件初始化 */
        $map = array();
        $map  = array('config_status' => 1);
        
        $config_list = C('CONFIG_GROUP_LIST');
        
        $config_list = empty($config_list) ? '' : preg_replace('/\s(?=\s)/', ',', $config_list);
        
        $configTemp = empty($config_list) ? array() : explode(',', $config_list);
        
        $config_group = array();
        foreach ($configTemp as $key=>$value){
            $tmp = explode(':', trim($value));
            $config_group[$tmp[0]]['tab_name'] = $tmp[1];
            
            $map['config_group'] = $tmp[0];
            $config_group[$tmp[0]]['config'] = M("Config")->where($map)->select();
        }
        
        $this->assign('list', $config_group);
        $this->meta_title = '配置管理';
        $this->display();
        
    }
    
    /**
     * 新增系统配置
     * @author derek <693472824@qq.com>
     */
    public function add() {
        
        $configLogic = D('Config', 'Logic');
        $result = $configLogic->addConfig();
        if($result === false){
            $this->error('操作失败'.$configLogic->getError());
        }else{
            $this->success('操作成功', U('index'));
        }
        
    }
    
    /**
     * 修改系统配置
     * @author derek <693472824@qq.com>
     */
    public function edit(){
        $configLogic = D('Config', 'Logic');
        $result = $configLogic->editConfig();
        if($result === false){
            $this->error('操作失败'.$configLogic->getError());
        }else{
            $this->success('操作成功', U('index'));
        }
    }
    
    
}